package com.neuedu.jxcboot.common.bean;

import java.io.Serializable;

/**
 * 
 * @author chens
 *
 * @param <T>
 */
public class CommonResult<T> implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1820235454460459048L;

	/** 成功与否 */
	private Boolean success;

	/**
	 * 错误码
	 */
	private Integer code;

	/**
	 * 错误提示
	 */
	private String message;

	/**
	 * 返回数据
	 */
	private T data;

	public Boolean getSuccess() {
		return success;
	}

	public void setSuccess(Boolean success) {
		this.success = success;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public static CommonResult<Object> success(Object object) {
		return success(200, object);
	}

	public static CommonResult<Object> success(Integer code, Object object) {
		CommonResult<Object> result = new CommonResult<>();
		result.setMessage("success");
		result.setCode(code);
		result.setSuccess(Boolean.TRUE);
		result.setData(object);
		return result;
	}

	public static CommonResult<Object> error(Object object) {
		return error(500, object);
	}

	public static CommonResult<Object> error(Integer code, Object object) {
		CommonResult<Object> result = new CommonResult<>();
		result.setMessage("error");
		result.setCode(code);
		result.setSuccess(Boolean.FALSE);
		result.setData(object);
		return result;
	}

}
